#!/bin/bash
# 本脚本只在首次部署MySQL时执行
# 初始化MySQL root账号

XPWD=`grep 'temporary password' /var/log/mysqld.log | awk '{print $NF}'`
echo $XPWD

mysql --connect-expired-password -uroot -p"$XPWD" -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '{{ mysql_root_password }}'"
mysql -uroot -p'{{ mysql_root_password }}'  -e  "GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY '{{ mysql_root_password }}' WITH GRANT OPTION"

mysql -h$(hostname -I | awk '{print $1}') -uroot -p'{{ mysql_root_password }}' -e "DROP USER 'root'@'localhost'"
mysql -uroot -p'{{ mysql_root_password }}'  -e "select user,host from mysql.user"
